import axios from "axios"
import qs from "querystring"

// var baseUrl
// if (process.env.NODE_ENV == "development") {
//     baseUrl = ""
// } else {
//     baseUrl = ""
// }
//请求拦截
axios.interceptors.request.use(config => {
    // console.log(config)
    return config
})

//响应拦截
axios.interceptors.response.use(response => {
    // console.log(response.data)
    return response
})
export function get(url, params={}) {
    return new Promise((resolve, reject) => {
        axios.get(
            url,
            { params }
        ).then(res => {
            if (res.status == 200) {
                console.log(res.data)
                resolve(res.data)
            }
        }).catch(err => {
            reject(err)
        })
    })
}
export function post(url,params,isFile=false){
    let data = null
    return new Promise((resolve,reject)=>{
        if(isFile){
            let fd= new FormData()
            for(let key in params){
                fd.append(key,params[key])
            }
            data = fd
        }else{
            data=qs.stringify(params)
        }
        axios.post(url,data).then(res=>{
            if(res.status==200){
                console.log(res.data)
                resolve(res.data)
            }
        }).catch(err=>{
            reject(err)
        })
    })
}